// import axios from '../handleService'
import axios from '../handleService'
import request from '../request'

export default {
  // 项目管理
  // 列表
  getProjectList: (params) => axios.post('/api/project/listOfPage', params),
  // 新增
  setProject: (params) => axios.post('/api/project/', params),
  // 详情
  getProjectById: (id) => axios.get(`/api/project/${id}`),
  // 更新
  updateProject: ({ id, params }) => axios.put(`/api/project/${id}`, params),
  // 删除
  deleteProject: (ids) =>
    axios.delete('/api/project/batchDelete', { data: ids }),

  // 数据源
  // 列表
  getDataSourceList: (params) =>
    axios.post('/api/connection/listOfPage', params),
  // 新增
  setDataSource: (params) => axios.post('/api/connection/', params),
  // 详情
  getDataSourceById: (id) => axios.get(`/api/connection/${id}`),
  // 更新
  updateDataSource: ({ id, params }) => axios.put(`/api/connection/${id}`, params),
  // 删除
  deleteDataSource: (ids) =>
    axios.delete('/api/connection/batchDelete', { data: ids }),
  // 测试连接
  testConnect: params => axios.post('/api/connection/test', params),
  // 连接类型
  getConnectionTypes: id => axios.get(`/api/connection/connectionTypes`),
  // 当前项目下全部连接列表
  getConnectionListByProject: id => axios.get(`/api/connection/listByProject/${id}`),

  // API数据源
  // 获取api层级树
  getApiTree: id => axios.get(`/api/api-manage/tree/${id}`),
  // 新建目录
  postApiCatalog: (params) => axios.post('/api/api-manage/catalog', params),
  // 修改目录
  putApiCatalog: (params) => axios.put('/api/api-manage/catalog', params),
  // 删除目录
  deleteApiCatalog: (id) => axios.delete(`/api/api-manage/catalog/${id}`),
  // 导出API
  getApiExport: (params) => axios.get(`/api/api-manage/export`, { params }),
  // 导入API
  postApiImport: (params) =>
    axios.post(`/api/api-manage/importData`, params, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    }),
  getAllApiDatabases: (id) => axios.get(`/api/connection/listByProject/${id}`),
  // 获取数据库结构
  postApiDatabases: (params) => axios.post('/api/api-manage/inner/databases', params),
  // 获取表
  postApiTables: (params) => axios.post('/api/api-manage/inner/tables', params),
  // 获取字段
  postApiColumns: (params) => axios.post('/api/api-manage/inner/columns', params),
  // 获取数据库结构
  postApiData: params => axios.post('/api/api-manage/inner/data', params),
  // 获取api详情
  getApiDetails: (id) => axios.get(`/api/api-manage/${id}`),
  // 删除api
  deleteApi: (id) => axios.delete(`/api/api-manage/${id}`),
  // 新建api
  postAddApi: (params) => axios.post(`/api/api-manage/`, params),
  // 编辑api
  putEditApi: (params) => axios.put(`/api/api-manage/`, params),

  // API监控
  // 接口访问分页列表
  postLogList: (params) => axios.post('/api/access-log/list', params),

  // 资源管理
  // 分页列表
  postEngineListOfPage: (params) => axios.post('/api/engineInfo/listOfPage', params),
  // 批量删除
  deleteEngineBatchDelete: (ids) => axios.delete('/api/engineInfo/batchDelete', { data: ids }),
  // 详情
  getEngineInfoId: (id) => axios.get(`/api/engineInfo/${id}`),
  // 更新
  putEngineInfoId: (params) => axios.put(`/api/engineInfo/${params.id}`, params),
  // 删除
  deleteEngineInfoId: (id) => axios.delete(`/api/engineInfo/${id}`),
  // 新增
  postAddEngineInfo: (params) => axios.post(`/api/engineInfo/`, params),

  // 接口令牌
  // 列表
  getAccessTokenList: (params) => axios.get(`/api/third/client/list`, { params }),
  // 新增 
  setAccessToken: (params) => axios.post('/api/third/client/', params),
  // 更新
  updateAccessToken: ({ id, params }) => axios.put(`/api/third/client?id=${id}`, params),
  // 启用
  startAccessToken: params => axios.put(`/api/third/client/start`, params),
  // 停用
  stopAccessToken: params => axios.put(`/api/third/client/stop`, params),
  // 删除 
  deleteAccessToken: ids => axios.delete(`/api/third/client`, { data: ids })
}
